package com.example.administrator.myapplication;

import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private SeekBar mSeekBar;
    private MediaPlayer mMediaPlayer;
    private AudioManager mAudioManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.start).setOnClickListener(this);
        findViewById(R.id.stop).setOnClickListener(this);
        findViewById(R.id.change).setOnClickListener(this);
        mSeekBar = (SeekBar) findViewById(R.id.seekBar);

        //得到音频管理类
        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        //得到某种声音的最大值
        int max =mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        //得到当前音量
        int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        mSeekBar.setMax(max);
        mSeekBar.setProgress(volume);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.start:
                break;
            case R.id.stop:
                break;
            case R.id.change:
                break;
        }
    }
    //Seekbar进度条改变时间
    private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,progress,AudioManager.FLAG_SHOW_UI);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    };
    //Shared Preferences的使用
    private void save(){
        SharedPreferences sharedPref = this.getPreferences(MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt("number",1);
        editor.commit();
    }
    private void load(){
        SharedPreferences sharedPref = this.getPreferences(MODE_PRIVATE);
        sharedPref.getInt("number",0);
    }
}
